<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Digest - Modules that calculate message digests - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/Digest">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="Digest.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/Digest">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/Digest">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/Digest">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/Digest">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/Digest">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/Digest">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/Digest">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/Digest">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/Digest">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/Digest">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/Digest">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/Digest">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/Digest">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/Digest">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/Digest">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/Digest">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/Digest">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/Digest">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/Digest">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/Digest">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/Digest">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/Digest">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/Digest">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/Digest">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/Digest">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/Digest">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/Digest">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/Digest">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/Digest">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/Digest">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/Digest">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/Digest">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/Digest">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/Digest">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/Digest">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/Digest">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/Digest">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/Digest">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/Digest">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/Digest">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/Digest">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/Digest">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/Digest">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/Digest">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/Digest">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/Digest">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/Digest">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/Digest">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/Digest">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/Digest">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/Digest">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/Digest">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/Digest">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/Digest">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/Digest">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/Digest">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/Digest">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/Digest">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/Digest">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/Digest">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/Digest">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/Digest">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/Digest">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/Digest">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/Digest">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/Digest">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/Digest">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/Digest">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/Digest">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/Digest">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/Digest">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/Digest">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/Digest">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/Digest">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/Digest">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/Digest">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/Digest">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/Digest">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/Digest">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/Digest">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="Digest.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/Digest">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/Digest">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/Digest">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/Digest">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/Digest">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/Digest">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/Digest">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/Digest">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/Digest">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/Digest">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/Digest">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/Digest">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/Digest">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/Digest">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/Digest">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/Digest">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/Digest">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/Digest">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/Digest">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/Digest">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/Digest">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/Digest">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/Digest">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/Digest">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/Digest">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/Digest">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/Digest">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/Digest">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/Digest">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/Digest">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/Digest">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/Digest">5.35.1</a>
          <a class="dropdown-item active" href="Digest.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="Digest.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="Digest.html">Digest</a>
          <div id="more">
            (<a href="Digest.txt">source</a>,
            <a href="https://metacpan.org/pod/Digest">CPAN</a>)
          </div>
            <div id="moduleversion">version 1.19</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="Digest.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Digest.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Digest.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Digest.html#OO-INTERFACE">OO INTERFACE</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Digest.html#Digest-speed">Digest speed</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Digest.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Digest.html#AUTHOR">AUTHOR</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="Digest.html#NAME">#</a>NAME</h1>

<p>Digest - Modules that calculate message digests</p>

<h1 id="SYNOPSIS"><a class="permalink" href="Digest.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>$md5  = Digest-&gt;new(&quot;MD5&quot;);
$sha1 = Digest-&gt;new(&quot;SHA-1&quot;);
$sha256 = Digest-&gt;new(&quot;SHA-256&quot;);
$sha384 = Digest-&gt;new(&quot;SHA-384&quot;);
$sha512 = Digest-&gt;new(&quot;SHA-512&quot;);

$hmac = Digest-&gt;HMAC_MD5($key);</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="Digest.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>The <code>Digest::</code> modules calculate digests, also called &quot;fingerprints&quot; or &quot;hashes&quot;, of some data, called a message. The digest is (usually) some small/fixed size string. The actual size of the digest depend of the algorithm used. The message is simply a sequence of arbitrary bytes or bits.</p>

<p>An important property of the digest algorithms is that the digest is <i>likely</i> to change if the message change in some way. Another property is that digest functions are one-way functions, that is it should be <i>hard</i> to find a message that correspond to some given digest. Algorithms differ in how &quot;likely&quot; and how &quot;hard&quot;, as well as how efficient they are to compute.</p>

<p>Note that the properties of the algorithms change over time, as the algorithms are analyzed and machines grow faster. If your application for instance depends on it being &quot;impossible&quot; to generate the same digest for a different message it is wise to make it easy to plug in stronger algorithms as the one used grow weaker. Using the interface documented here should make it easy to change algorithms later.</p>

<p>All <code>Digest::</code> modules provide the same programming interface. A functional interface for simple use, as well as an object oriented interface that can handle messages of arbitrary length and which can read files directly.</p>

<p>The digest can be delivered in three formats:</p>

<dl>

<dt id="binary"><a class="permalink" href="Digest.html#binary">#</a><i>binary</i></dt>
<dd>

<p>This is the most compact form, but it is not well suited for printing or embedding in places that can&#39;t handle arbitrary data.</p>

</dd>
<dt id="hex"><a class="permalink" href="Digest.html#hex">#</a><i>hex</i></dt>
<dd>

<p>A twice as long string of lowercase hexadecimal digits.</p>

</dd>
<dt id="base64"><a class="permalink" href="Digest.html#base64">#</a><i>base64</i></dt>
<dd>

<p>A string of portable printable characters. This is the base64 encoded representation of the digest with any trailing padding removed. The string will be about 30% longer than the binary version. <a href="./MIME::Base64.html">MIME::Base64</a> tells you more about this encoding.</p>

</dd>
</dl>

<p>The functional interface is simply importable functions with the same name as the algorithm. The functions take the message as argument and return the digest. Example:</p>

<pre><code>use Digest::MD5 qw(md5);
$digest = md5($message);</code></pre>

<p>There are also versions of the functions with &quot;_hex&quot; or &quot;_base64&quot; appended to the name, which returns the digest in the indicated form.</p>

<h1 id="OO-INTERFACE"><a class="permalink" href="Digest.html#OO-INTERFACE">#</a><a id="OO"></a>OO INTERFACE</h1>

<p>The following methods are available for all <code>Digest::</code> modules:</p>

<dl>

<dt id="$ctx-=-Digest-&gt;XXX($arg,...)"><a class="permalink" href="Digest.html#$ctx-=-Digest-%3EXXX($arg,...)">#</a><a id="ctx-Digest-XXX-arg"></a>$ctx = Digest-&gt;XXX($arg,...)</dt>
<dd>

</dd>
<dt id="$ctx-=-Digest-&gt;new(XXX-=&gt;-$arg,...)"><a class="permalink" href="Digest.html#$ctx-=-Digest-%3Enew(XXX-=%3E-$arg,...)">#</a><a id="ctx-Digest-new-XXX-arg"></a>$ctx = Digest-&gt;new(XXX =&gt; $arg,...)</dt>
<dd>

</dd>
<dt id="$ctx-=-Digest::XXX-&gt;new($arg,...)"><a class="permalink" href="Digest.html#$ctx-=-Digest::XXX-%3Enew($arg,...)">#</a><a id="ctx-Digest::XXX-new-arg"></a>$ctx = Digest::XXX-&gt;new($arg,...)</dt>
<dd>

<p>The constructor returns some object that encapsulate the state of the message-digest algorithm. You can add data to the object and finally ask for the digest. The &quot;XXX&quot; should of course be replaced by the proper name of the digest algorithm you want to use.</p>

<p>The two first forms are simply syntactic sugar which automatically load the right module on first use. The second form allow you to use algorithm names which contains letters which are not legal perl identifiers, e.g. &quot;SHA-1&quot;. If no implementation for the given algorithm can be found, then an exception is raised.</p>

<p>To know what arguments (if any) the constructor takes (the <code>$args,...</code> above) consult the docs for the specific digest implementation.</p>

<p>If new() is called as an instance method (i.e. $ctx-&gt;new) it will just reset the state the object to the state of a newly created object. No new object is created in this case, and the return value is the reference to the object (i.e. $ctx).</p>

</dd>
<dt id="$other_ctx-=-$ctx-&gt;clone"><a class="permalink" href="Digest.html#$other_ctx-=-$ctx-%3Eclone">#</a><a id="other_ctx-ctx-clone"></a>$other_ctx = $ctx-&gt;clone</dt>
<dd>

<p>The clone method creates a copy of the digest state object and returns a reference to the copy.</p>

</dd>
<dt id="$ctx-&gt;reset"><a class="permalink" href="Digest.html#$ctx-%3Ereset">#</a><a id="reset"></a><a id="ctx-reset"></a>$ctx-&gt;reset</dt>
<dd>

<p>This is just an alias for $ctx-&gt;new.</p>

</dd>
<dt id="$ctx-&gt;add(-$data-)"><a class="permalink" href="Digest.html#$ctx-%3Eadd(-$data-)">#</a><a id="add"></a><a id="ctx-add-data"></a>$ctx-&gt;add( $data )</dt>
<dd>

</dd>
<dt id="$ctx-&gt;add(-$chunk1,-$chunk2,-...-)"><a class="permalink" href="Digest.html#$ctx-%3Eadd(-$chunk1,-$chunk2,-...-)">#</a><a id="add1"></a><a id="ctx-add-chunk1-chunk2"></a>$ctx-&gt;add( $chunk1, $chunk2, ... )</dt>
<dd>

<p>The string value of the $data provided as argument is appended to the message we calculate the digest for. The return value is the $ctx object itself.</p>

<p>If more arguments are provided then they are all appended to the message, thus all these lines will have the same effect on the state of the $ctx object:</p>

<pre><code>$ctx-&gt;add(&quot;a&quot;); $ctx-&gt;add(&quot;b&quot;); $ctx-&gt;add(&quot;c&quot;);
$ctx-&gt;add(&quot;a&quot;)-&gt;add(&quot;b&quot;)-&gt;add(&quot;c&quot;);
$ctx-&gt;add(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;);
$ctx-&gt;add(&quot;abc&quot;);</code></pre>

<p>Most algorithms are only defined for strings of bytes and this method might therefore croak if the provided arguments contain chars with ordinal number above 255.</p>

</dd>
<dt id="$ctx-&gt;addfile(-$io_handle-)"><a class="permalink" href="Digest.html#$ctx-%3Eaddfile(-$io_handle-)">#</a><a id="addfile"></a><a id="ctx-addfile-io_handle"></a>$ctx-&gt;addfile( $io_handle )</dt>
<dd>

<p>The $io_handle is read until EOF and the content is appended to the message we calculate the digest for. The return value is the $ctx object itself.</p>

<p>The addfile() method will croak() if it fails reading data for some reason. If it croaks it is unpredictable what the state of the $ctx object will be in. The addfile() method might have been able to read the file partially before it failed. It is probably wise to discard or reset the $ctx object if this occurs.</p>

<p>In most cases you want to make sure that the $io_handle is in &quot;binmode&quot; before you pass it as argument to the addfile() method.</p>

</dd>
<dt id="$ctx-&gt;add_bits(-$data,-$nbits-)"><a class="permalink" href="Digest.html#$ctx-%3Eadd_bits(-$data,-$nbits-)">#</a><a id="add_bits"></a><a id="ctx-add_bits-data-nbits"></a>$ctx-&gt;add_bits( $data, $nbits )</dt>
<dd>

</dd>
<dt id="$ctx-&gt;add_bits(-$bitstring-)"><a class="permalink" href="Digest.html#$ctx-%3Eadd_bits(-$bitstring-)">#</a><a id="add_bits1"></a><a id="ctx-add_bits-bitstring"></a>$ctx-&gt;add_bits( $bitstring )</dt>
<dd>

<p>The add_bits() method is an alternative to add() that allow partial bytes to be appended to the message. Most users can just ignore this method since typical applications involve only whole-byte data.</p>

<p>The two argument form of add_bits() will add the first $nbits bits from $data. For the last potentially partial byte only the high order <code>$nbits % 8</code> bits are used. If $nbits is greater than <code>length($data) * 8</code>, then this method would do the same as <code>$ctx-&gt;add($data)</code>.</p>

<p>The one argument form of add_bits() takes a $bitstring of &quot;1&quot; and &quot;0&quot; chars as argument. It&#39;s a shorthand for <code>$ctx-&gt;add_bits(pack(&quot;B*&quot;, $bitstring), length($bitstring))</code>.</p>

<p>The return value is the $ctx object itself.</p>

<p>This example shows two calls that should have the same effect:</p>

<pre><code>$ctx-&gt;add_bits(&quot;111100001010&quot;);
$ctx-&gt;add_bits(&quot;\xF0\xA0&quot;, 12);</code></pre>

<p>Most digest algorithms are byte based and for these it is not possible to add bits that are not a multiple of 8, and the add_bits() method will croak if you try.</p>

</dd>
<dt id="$ctx-&gt;digest"><a class="permalink" href="Digest.html#$ctx-%3Edigest">#</a><a id="digest"></a><a id="ctx-digest"></a>$ctx-&gt;digest</dt>
<dd>

<p>Return the binary digest for the message.</p>

<p>Note that the <code>digest</code> operation is effectively a destructive, read-once operation. Once it has been performed, the $ctx object is automatically <code>reset</code> and can be used to calculate another digest value. Call $ctx-&gt;clone-&gt;digest if you want to calculate the digest without resetting the digest state.</p>

</dd>
<dt id="$ctx-&gt;hexdigest"><a class="permalink" href="Digest.html#$ctx-%3Ehexdigest">#</a><a id="hexdigest"></a><a id="ctx-hexdigest"></a>$ctx-&gt;hexdigest</dt>
<dd>

<p>Same as $ctx-&gt;digest, but will return the digest in hexadecimal form.</p>

</dd>
<dt id="$ctx-&gt;b64digest"><a class="permalink" href="Digest.html#$ctx-%3Eb64digest">#</a><a id="b64digest"></a><a id="ctx-b64digest"></a>$ctx-&gt;b64digest</dt>
<dd>

<p>Same as $ctx-&gt;digest, but will return the digest as a base64 encoded string without padding.</p>

</dd>
<dt id="$ctx-&gt;base64_padded_digest"><a class="permalink" href="Digest.html#$ctx-%3Ebase64_padded_digest">#</a><a id="base64_padded_digest"></a><a id="ctx-base64_padded_digest"></a>$ctx-&gt;base64_padded_digest</dt>
<dd>

<p>Same as $ctx-&gt;digest, but will return the digest as a base64 encoded string.</p>

</dd>
</dl>

<h1 id="Digest-speed"><a class="permalink" href="Digest.html#Digest-speed">#</a><a id="Digest"></a>Digest speed</h1>

<p>This table should give some indication on the relative speed of different algorithms. It is sorted by throughput based on a benchmark done with of some implementations of this API:</p>

<pre><code class="plaintext">Algorithm      Size    Implementation                  MB/s

MD4            128     Digest::MD4 v1.3               165.0
MD5            128     Digest::MD5 v2.33               98.8
SHA-256        256     Digest::SHA2 v1.1.0             66.7
SHA-1          160     Digest::SHA v4.3.1              58.9
SHA-1          160     Digest::SHA1 v2.10              48.8
SHA-256        256     Digest::SHA v4.3.1              41.3
Haval-256      256     Digest::Haval256 v1.0.4         39.8
SHA-384        384     Digest::SHA2 v1.1.0             19.6
SHA-512        512     Digest::SHA2 v1.1.0             19.3
SHA-384        384     Digest::SHA v4.3.1              19.2
SHA-512        512     Digest::SHA v4.3.1              19.2
Whirlpool      512     Digest::Whirlpool v1.0.2        13.0
MD2            128     Digest::MD2 v2.03                9.5

Adler-32        32     Digest::Adler32 v0.03            1.3
CRC-16          16     Digest::CRC v0.05                1.1
CRC-32          32     Digest::CRC v0.05                1.1
MD5            128     Digest::Perl::MD5 v1.5           1.0
CRC-CCITT       16     Digest::CRC v0.05                0.8</code></pre>

<p>These numbers was achieved Apr 2004 with ActivePerl-5.8.3 running under Linux on a P4 2.8 GHz CPU. The last 5 entries differ by being pure perl implementations of the algorithms, which explains why they are so slow.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="Digest.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="./Digest::Adler32.html">Digest::Adler32</a>, <a href="./Digest::CRC.html">Digest::CRC</a>, <a href="./Digest::Haval256.html">Digest::Haval256</a>, <a href="./Digest::HMAC.html">Digest::HMAC</a>, <a href="./Digest::MD2.html">Digest::MD2</a>, <a href="./Digest::MD4.html">Digest::MD4</a>, <a href="./Digest::MD5.html">Digest::MD5</a>, <a href="./Digest::SHA.html">Digest::SHA</a>, <a href="./Digest::SHA1.html">Digest::SHA1</a>, <a href="./Digest::SHA2.html">Digest::SHA2</a>, <a href="./Digest::Whirlpool.html">Digest::Whirlpool</a></p>

<p>New digest implementations should consider subclassing from <a href="./Digest::base.html">Digest::base</a>.</p>

<p><a href="./MIME::Base64.html">MIME::Base64</a></p>

<p>http://en.wikipedia.org/wiki/Cryptographic_hash_function</p>

<h1 id="AUTHOR"><a class="permalink" href="Digest.html#AUTHOR">#</a>AUTHOR</h1>

<p>Gisle Aas &lt;gisle@aas.no&gt;</p>

<p>The <code>Digest::</code> interface is based on the interface originally developed by Neil Winton for his <code>MD5</code> module.</p>

<p>This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p>

<pre><code class="plaintext">Copyright 1998-2006 Gisle Aas.
Copyright 1995,1996 Neil Winton.</code></pre>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
